﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPFTools.Controls
{
    /// <summary>
    /// 自定义文本框
    /// </summary>
    [TemplatePart(Name = "PART_ContentHost", Type = typeof(ScrollViewer))]
    public class FTextBox : TextBox
    {
        //引用模板元素
        private const string PART_ContentHost = "PART_ContentHost"; //主要部分
        private ScrollViewer scrollViewer;

        static FTextBox()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(FTextBox), new FrameworkPropertyMetadata(typeof(FTextBox)));
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            scrollViewer = GetTemplateChild(PART_ContentHost) as ScrollViewer;
        }

        protected override void OnGotFocus(RoutedEventArgs e)
        {
            // base.OnGotFocus(e);
            scrollViewer.Focus();
        }



        public static readonly DependencyProperty CornerRadiusProperty =
               DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(FTextBox), new PropertyMetadata(new CornerRadius(0)));
        /// <summary>
        /// 圆角大小,左上，右上，右下，左下
        /// </summary>
        public CornerRadius CornerRadius
        {
            get { return (CornerRadius)GetValue(CornerRadiusProperty); }
            set { SetValue(CornerRadiusProperty, value); }
        }



        public string WaterMark
        {
            get { return (string)GetValue(WaterMarkProperty); }
            set { SetValue(WaterMarkProperty, value); }
        }

        

        /// <summary>
        /// 水印内容 
        /// </summary>
        public static readonly DependencyProperty WaterMarkProperty =
            DependencyProperty.Register("WaterMark", typeof(string), typeof(FTextBox), new PropertyMetadata(""));


        public string Label
        {
            get { return (string)GetValue(LabelProperty); }
            set { SetValue(LabelProperty, value); }
        }

       /// <summary>
       /// Label标签的内容
       /// </summary>
        public static readonly DependencyProperty LabelProperty =
            DependencyProperty.Register("Label", typeof(string), typeof(FTextBox), new PropertyMetadata(""));

        public double LabelWidth
        {
            get { return (double)GetValue(LabelWidthProperty); }
            set { SetValue(LabelWidthProperty, value); }
        }

        /// <summary>
        /// Label标签的宽度
        /// </summary>
        public static readonly DependencyProperty LabelWidthProperty =
            DependencyProperty.Register("LabelWidth", typeof(double), typeof(FTextBox), new PropertyMetadata(40.0));

        

    }
}
